var isSpecialAccount = '0'; // 特殊账号
var policyID = ''; // 政策编号
var copyObTypeNum = $.trim(''); // 要复制的类型
var curUser = 'tehangair'; // 当前登录用户
var allNoOpenTicketProiders = 'jinriguoji7|huanjitong123|zjltgj|tongtong03|testguoji112'; //
var currType = "元"; // 币种符号
var currTypeTemp = currType; // 币种符号v
var currencyRate = "1"; // 货币汇率
var currencyRateDefaultRate = "1"; // 货币汇率
var autoState = "5";// 政策状态
var isExtProvider = "False" == "True"; // 是否为境外供应商
var IsAddEtermConfigSupply = "False" == "True"; // 境内供应商是否在配置内
var CanAutoChangePnrAirLines = "CA,MU,CZ,HU,CN,JD,MF,FM,HO,ZH,3U";// 可以设置自动换编的航司

$(function(){
	
	$("#addOne").click(function () {
    	var startDate = $('#outboundTravelDateExcludeStartStr').val().split('-').join('');
    	var endDate = $('#outboundTravelDateExcludeEndStr').val().split('-').join('');
    	if (!startDate || !endDate){
    		return;
    	}
        $("#select-result").append("<a class='selectedInfor radius' onclick='$(this).remove()'>" + startDate + "-" + endDate + "<em></em></a>");
        $('#outboundTravelDateExcludeStartStr').val("");
        $('#outboundTravelDateExcludeEndStr').val("");
	});
	
	 // flightNo验证    
    jQuery.validator.addMethod("flightNo", function(value, element) {
    	if(value==""){
    		return true;
    	}
    	var str = value.split("/");
    	var reg1=/^[A-Z]{2}[0-9]{3,4}$/;
    	var reg2=/^([A-Z]{2}\*)|([A-Z]{2}[0-9]{1}\*)|([A-Z]{2}[0-9]{2}\*)|([A-Z]{2}[0-9]{3}\*)$/;
    	var reg3=/^([A-Z]{2}[0-9]{3}-[A-Z]{2}[0-9]{3,4})|([A-Z]{2}[0-9]{4}-[A-Z]{2}[0-9]{4})$/;
    	var flag = true;
    	for (var i = 0; i < str.length; i++) {
			if(str[i]=="" || reg1.test(str[i]) || reg2.test(str[i]) || reg3.test(str[i])){
				continue;
			}else{
				flag = false;
				break;
			}
		}
    	return flag;    
    
    }, "格式有错");
    // flightLine航线验证    
    jQuery.validator.addMethod("flightLine", function(value, element) {
    	if(value==""){
    		return true;
    	}
    	var str = value.split("/");
    	var reg=/^[A-Z]{3}-[A-Z]{3}$/;
    	var flag = true;
    	for (var i = 0; i < str.length; i++) {
			if(str[i]=="" || reg.test(str[i])){
				continue;
			}else{
				flag = false;
				break;
			}
		}
    	return flag;    
    }, "格式有错");
    
    // 验证日期 validDate
     jQuery.validator.addMethod("validDate", function(value, element) {
    	if(value==""){
    		return true;
    	}
    	var str = value.split("/");
    	var reg=/^(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)$/;
    	var flag = true;
    	for (var i = 0; i < str.length; i++) {
			if(str[i]=="" || reg.test(str[i])){
				continue;
			}else{
				flag = false;
				break;
			}
		}
    	return flag;    
    }, "日期格式有错");
     
    $("#form").validate({
		debug:true,
		onkeyup:false,
		focusCleanup:false,
		success:"valid",
		invalidHandler: function(form, validator) {return false;},
		submitHandler: function(form) {
			$('#departure').val($('[ref=select]', $('#dv_DepCity')).find('dd').html());
			$('#departureExclude').val($('[ref=except]', $('#dv_DepCity')).find('dd').html());
			$('#departureCabins').val($('div.sc', $('#dv_DepCity')).html() === '您还没选择舱位' ? '' : $('div.sc', $('#dv_DepCity')).html());
            $('#arrival').val($('[ref=select]', $('#dv_ArrCity')).find('dd').html());
            $('#arrivalExclude').val($('[ref=except]', $('#dv_ArrCity')).find('dd').html());
            $('#transfer').val($('[ref=select]', $('#dv_TransferCity')).find('dd').html());
            $('#transferExclude').val($('[ref=except]', $('#dv_TransferCity')).find('dd').html());
            $('#arrivalCabins').val($('div.sc', $('#dv_TransferCity')).html() === '您还没选择舱位' ? '' : $('div.sc', $('#dv_TransferCity')).html());
            $("input[name='journeyType']").val($("input[name='rd_ObTypeNum'][loaded='1']").val());
			var json = $('#form').serialize();  
	        $.ajax({  
	          type : 'post',  
	          contentType : 'application/json',  
	          url : 'save?' + json,  
	          success : function(data) {
	        	  var rsult = jQuery.parseJSON(data);
	        	  if (rsult.success) {
	        		  alert("保存成功！");
	        		  window.parent.location.reload();
	        	  } else 
	        		  alert("保存失败!" + rsult.message);
	          },  
	          error : function(data) {  
	              alert("保存失败！")  
	          }  
	        });
	        return false;
		},
	});
});
function buildDateCommision(){
	var ticketingDateCommision = '';
	$("#select-result").children().each(function(){
		ticketingDateCommision += $(this).html().replace('<em></em>','') + ",";
	});
	$('#ticketingDateCommision').val(ticketingDateCommision.substring(0, ticketingDateCommision.length-1));
}
function resumeDateCommision(){
	var commisions = $('#ticketingDateCommision').val().split(",");
	for (var i=0;i<commisions.length;i++){
		if (commisions[i]){
			$("#select-result").append("<a class='selectedInfor radius' onclick='$(this).remove()'>" + commisions[i] + "<em></em></a>");
		}
	}
}
function AirportCode(name, hidden) {
	
	//alert(name+"    "+hidden);
	
    jElass.exec({
        input: name,
        hidden: hidden,
        url: '/airport/search',
	    error : '很抱歉 暂时没有匹配的城市',width: 100
    });
}